package cn.lili.common.security;

import cn.lili.common.security.enums.SceneEnums;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * token角色
 *
 * @author Chopper
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AuthUser implements Serializable {

    private static final long serialVersionUID = 582441893336003319L;

    /**
     * 用户名
     */
    private String username;

    /**
     * 昵称
     */
    private String nickName;

    /**
     * 头像
     */
    private String face;

    /**
     * 用户id
     */
    private String id;

    /**
     * 长期有效（用于手机app登录场景或者信任场景等）
     */
    private Boolean longTerm = false;

    /**
     * 角色场景
     *
     * @see SceneEnums
     */
    private SceneEnums scene;

    /**
     * 是否是超级管理员
     */
    private Boolean isSuper = false;


    /**
     * 场景下的id 如果为店铺/供应商 则这里配置的是供应商商家或者店铺id
     * storeId supplierId memberId 等
     * 如果为管理平台端，则为-1
     */
    private String extendId;

    /**
     * 场景下的名称
     * storeName
     */
    private String extendName;

    /**
     * 租户id
     */
    private String tenantId;

    /**
     * 飞语openid
     */
    private String openId;

    /**
     * 是否vip
     */
    private Boolean isVip = false;


    public String getExtendId() {
        if (scene.equals(SceneEnums.MANAGER)) {
            return "-1";
        }
        if (extendId == null) {
            return id;
        }
        return extendId;
    }

    public AuthUser(String username, String id, String nickName, String face, SceneEnums role) {
        this.username = username;
        this.face = face;
        this.id = id;
        this.scene = role;
        this.nickName = nickName;
    }

    public AuthUser(String username, String id, String face, SceneEnums manager, String nickName, Boolean isSuper) {
        this.username = username;
        this.id = id;
        this.face = face;
        this.scene = manager;
        this.isSuper = isSuper;
        this.nickName = nickName;
    }

}
